@Component
public class WeChatMessageHandler implements WxMpMessageHandler {

    @Autowired
    private ChatClient chatClient;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) {
        // 自动回复文本消息
        System.out.println("接收到消息：" + wxMessage.getContent());

        // 使用 chatClient 构建回复内容
        Flux<String> reply = chatClient.prompt()
                .user(wxMessage.getContent())
                .stream()
                .content();

        // 将 Flux<String> 转换为字符串
        StringBuilder replyContent = new StringBuilder();
        reply.subscribe(replyContent::append);

        return WxMpXmlOutMessage.TEXT()
                .content(replyContent.toString())
                .fromUser(wxMessage.getToUser())
                .toUser(wxMessage.getFromUser())
                .build();
    }
}